//go:build ignore

//go:generate go run migrate.go

// 编译前 执行生成代码
package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gen"
	"gorm.io/gorm"
)

func main() {
	outPath := fmt.Sprintf("internal/data")
	modelPkgPath := fmt.Sprintf("internal/data")

	dsn := "root:root123456!@tcp(127.0.0.1:3306)/micro?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}

	g := gen.NewGenerator(gen.Config{
		OutPath:           outPath,
		OutFile:           "gen.go",
		ModelPkgPath:      modelPkgPath,
		Mode:              gen.WithDefaultQuery | gen.WithQueryInterface,
		FieldNullable:     true,
		FieldCoverable:    true,
		FieldWithIndexTag: true,
		FieldWithTypeTag:  true,
	})
	g.UseDB(db)
	g.GenerateAllTable()
	g.Execute()
	fmt.Printf("✅ %s模型生成完成！文件已保存到 %s/gen.go\n", outPath)
}
